package com.study.component2;

import com.study.component2.MyBean6;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @Author tanglingyu
 * @Date: 2021/09/01/ 11:00
 * @Description
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
      throws BeansException {
    DefaultListableBeanFactory registry = (DefaultListableBeanFactory) beanFactory;
    RootBeanDefinition userBeanDefinition = new RootBeanDefinition(MyBean6.class);
    userBeanDefinition.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
    registry.registerBeanDefinition("sb6", userBeanDefinition);
  }
}

